home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
BBS
/
HERMES
/
ProtMover6.1.cpt
/
ASCII
/
write.c
< prev
Wrap
Text File
|
1990-05-26
|
3KB
|
126 lines
/* ASCII Transfer External for Hermes © 1990 By John Raymonds.
Written in THINK C 4.0.1 as an example external for Hermes protocol
developers. Use of any code shown below in any program other than
an external to be used with Hermes requires written permission from
the author:
John Raymonds
76174,205 (Compuserve)
D3885 (AppleLink)
Comments and suggestions are welcome.
*/
#include <:Mac #includes:SerialDvr.h>
#include "Protocol.h"
#include "ASCII.h"
extern ProtoRecPtr PRP;
extern ProtoGloPtr PGP;
SendString(s)
register unsigned char *s;
{
register int i;
if (s) {
for (i = 1; i<=*s; i++) {
SendCharNow((int) *(s+i));
}
}
SendCharNow((int) '\r');
SendCharNow((int) '\n');
}
SendCharNow(c)
int c;
{
register ProtoGloPtr pgp;
pgp = PGP;
if (pgp->wbPosA >= 0) {
/* we can use the A buffer */
pgp->writeBuffA[pgp->wbPosA++] = c;
/* check if the buffer is full */
if (pgp->wbPosA == WRITEBUFFSIZE) {
/* write this buffer out and start using the other one */
FinishWrite();
pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffA);
pgp->MIOPout.ioReqCount = (long) WRITEBUFFSIZE;
if (!PRP->F.B.carrierLost) {
PBWrite(StripAddress(&pgp->MIOPout), TRUE);
}
pgp->wbPosA = -1;
}
}
else {
/* we can use the B buffer */
pgp->writeBuffB[pgp->wbPosB++] = c;
/* check if the buffer is full */
if (pgp->wbPosB == WRITEBUFFSIZE) {
/* write this buffer out and start using the other one */
FinishWrite();
pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffB);
pgp->MIOPout.ioReqCount = (long) WRITEBUFFSIZE;
if (!PRP->F.B.carrierLost) {
PBWrite(StripAddress(&pgp->MIOPout), TRUE);
}
pgp->wbPosB = -1;
}
}
}
FinishWrite()
{
register ProtoRecPtr prp;
register ProtoGloPtr pgp;
prp = PRP;
pgp = PGP;
if (pgp->wbPosA < 0) {
do {
if (prp->F.B.carrierLost) {
PBKillIO(StripAddress(&pgp->MIOPout), FALSE);
pgp->MIOPout.ioResult = 0;
}
Return(prp->timeOut, &pgp->SSR);
} while(pgp->MIOPout.ioResult == 1);
pgp->wbPosA = 0;
}
else if (pgp->wbPosB < 0) {
do {
if (prp->F.B.carrierLost) {
PBKillIO(StripAddress(&pgp->MIOPout), FALSE);
pgp->MIOPout.ioResult = 0;
}
Return(prp->timeOut, &pgp->SSR);
} while(pgp->MIOPout.ioResult == 1);
pgp->wbPosB = 0;
}
}
FlushWrite()
{
register ProtoGloPtr pgp;
pgp = PGP;
FinishWrite();
if (pgp->wbPosA > 0) {
pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffA);
pgp->MIOPout.ioReqCount = (long) pgp->wbPosA;
if (!PRP->F.B.carrierLost) {
PBWrite(StripAddress(&pgp->MIOPout), TRUE);
}
pgp->wbPosA = -1;
FinishWrite();
}
else if (pgp->wbPosB > 0) {
pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffB);
pgp->MIOPout.ioReqCount = (long) pgp->wbPosB;
if (!PRP->F.B.carrierLost) {
PBWrite(StripAddress(&pgp->MIOPout), TRUE);
}
pgp->wbPosB = -1;
FinishWrite();
}
}